#include "aerial\Game\GameObject\Weapon\TracingMissile.h"

#include "aerial\FlyObject.h"

const float TracingMissile::MinPowerRequire = 10.f;
const float TracingMissile::PPS = 400.f;


bool TracingMissile::available(FlyObject* fObj)
{
	return fObj->GetPower() >= MinPowerRequire;
}

TracingMissile::TracingMissile(float x0, float x1, float vx, float vy, FlyObject* fObj, FlyObject* _dest)
	: Weapon(x0, x1, vx, vy, fObj), missileState(Tracing), dest(_dest)
{
	psMissile = new hgeParticleSystem(&hgeResMan->GetParticleSystem("ps.inner")->info);
	psMissile->info.colColorStart.r = 0;
	psMissile->info.colColorStart.g = 0;
	psMissile->info.colColorStart.b = 1.0;
	
	psMissile->info.colColorEnd.r = 0;
	psMissile->info.colColorEnd.g = 0;
	psMissile->info.colColorEnd.b = 1.0;

	psMissile->info.nEmission = 100;
	psMissile->FireAt(T.x, T.y);
}

TracingMissile::~TracingMissile() { delete psMissile; }

bool TracingMissile::update(float dt)
{
	if (missileState == Tracing)
	{
		// calculate the speed and direction
		b2Vec2 posDest = dest->GetPosition();
		b2Vec2 d(posDest.x - T.x, posDest.y - T.y);
		// needn't to adjust angle
		D = d;	D.Normalize();
		//TODO SetSpeed(PPS);
	}
	return false;
}

void TracingMissile::render()
{
	psMissile->Render();
}